﻿using System;
using System.Text;
using System.Data;

using NguyenHoa.Web.App_Code;
using NguyenHoa.Domains;
using NguyenHoa.Services;

namespace NguyenHoa.Web.Pages
{
  public partial class ProductDetail : BasePage
  {
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack && !IsCallback)
      {
        if (Id == 0)
        {
          TList<Product> productList = new ProductService().GetAll();
          if (productList.Count > 0)
          {
            Response.Redirect("ProductDetail.aspx?id=" + productList[0].Id.ToString());
          }
        }

        LoadData();
      }
    }
    #endregion

    #region Methods
    private void LoadData()
    {
      #region Info
      TList<ProductLocale> plList = new ProductLocaleService().GetByProductId(Id);
      foreach (ProductLocale pl in plList)
      {
        if (pl.LanguageId == CurrentLanguage.Id)
        {
          ltrName.Text = pl.Name;
          ltrDescription.Text = pl.Description;
          ltrContent.Text = pl.Content;
        }
      }
      #endregion

      #region Photo
      Product product = new ProductService().GetById(Id);
      if (product != null && product.AlbumId.HasValue)
      {
        TList<Multimedia> mediaList = new MultimediaService().GetByAlbumId(product.AlbumId);
        rptSlideShow.DataSource = mediaList;
        rptSlideShow.DataBind();
      }
      #endregion
    }
    #endregion
  }
}
